
package com.google.code.sms.android.util;

import android.app.Activity;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;

/**
 * For API level >= 11. Show option menu ICS-style, using a popup menu anchored
 * to a given view.
 *
 * @author Sindre Mehus
 * @version $Id$
 */
public class PopupMenuHelperHoneycomb extends PopupMenuHelperBase {

    @Override
    public void showMenu(final Activity activity, View anchor, int menuResource) {
        PopupMenu popup = new PopupMenu(activity, anchor);

        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem menuItem) {
                return activity.onOptionsItemSelected(menuItem);
            }
        });
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(menuResource, popup.getMenu());

        activity.onPrepareOptionsMenu(popup.getMenu());
        popup.show();
    }

}
